/**
 * Created by huangxuehua on 2017/11/27.
 */
//$("header>div.goBack").click(function(){
//    window.history.back()
//})
var toast = new auiToast(); //初始化toast事件
var xpHome = new Vue({
    el:'#app',
    data:{
        isSetDefault:true,
        Params:{city:""}
    },
    methods: {
        //提交信息判断部分
        succeedBtn: function () {
            if (!xpHome.Params.consignee) {
                toast.custom({
                    title: "请输入姓名",
                    html: '',
                    duration: 2000
                });
                return false;
            }
            if(!nUtils.checkName(xpHome.Params.consignee)){
                toast.custom({
                    title: "名称格式错误",
                    html: '',
                    duration: 2000
                });
                return false;
            }
            if (!xpHome.Params.tel) {
                toast.custom({
                    title: "请输入手机号",
                    html: '',
                    duration: 2000
                });
                return false;
            }
            if(!nUtils.checkTel(xpHome.Params.tel)){
                toast.custom({
                    title: "手机号格式错误",
                    html: '',
                    duration: 2000
                });
                return false;
            }
            xpHome.Params.city = $("#value1").val();
            if (!xpHome.Params.city) {
                toast.custom({
                    title: "请选择城市",
                    html: '',
                    duration: 2000
                });
                return false;
            }
            if (!xpHome.Params.address) {
                toast.custom({
                    title: "请输入详细地址",
                    html: '',
                    duration: 2000
                });
                return false;
            }
            xpHome.submitAddress();
        },
        submitAddress:function(){//添加地址
            var city = $("#value1").val();
            var citys =  city.split(",");
            var params = {
                //"userid":userInfo.userid,
                "data[is_def]":xpHome.isSetDefault == true?1:0,
                "data[tel]":xpHome.Params.tel,
                "data[email]":xpHome.Params.email,
                "data[consignee]":xpHome.Params.consignee,
                "data[country]":"1",
                "data[province]":citys[0],
                "data[city]":citys[1],
                "data[district]":citys[2],
                "data[address]":xpHome.Params.address,
                //"_csrf":"qVcJxp_U_XxocoYS7bpg_FIAYbEL7dg7AwwV7s61Q92bI5Hqqa3hvFw4Hwose_7w71D7mpg_Fj1FUx1r9gj75A=="
            };

            $.ajax({
                url: nUrls.addAddress,
                type: 'POST',
                data:params,
                success: function (data) {
                    var result = eval('(' + data + ')');
                    if (result && result.code == 200) {
                        window.history.go(-1);
                    }
                },
                error: function () {
                    console.log("获取信息出错");
                }
            });
        },
        defaultBtn:function(){
            xpHome.isSetDefault=!xpHome .isSetDefault;

        },
        goOnLine:function(){  //断网刷新
            nUtils.onLine();
        }
    }
});

var area1 = new LArea();
area1.init({
    'trigger': '#demo1', //触发选择控件的文本框，同时选择完毕后name属性输出到该位置
    'valueTo': '#value1', //选择完毕后id属性输出到该位置
    'keys': {
        id: 'value',
        name: 'text'
    }, //绑定数据源相关字段 id对应valueTo的value属性输出 name对应trigger的value属性输出
    'type': 1, //数据源类型
    'data': LAreaData //数据源
});
area1.value=[1,13,3];//控制初始位置，注意：该方法并不会影响到input的value